<template>
  <div>
<h2>添加理财</h2>
<table>
  <tr>
    <td>项目名称</td>
    <td><input type="text" v-model="state.I_Name"></td>
  </tr>
  <tr>
    <td>年收益</td>
    <td><input type="text" v-model="state.I_Year"></td>
  </tr>
  <tr>
    <td>月收益</td>
    <td><input type="text" v-model="state.I_Month"></td>
  </tr>
  <tr>
    <td>最低金额</td>
    <td><input type="text" v-model="state.I_MinMoney"></td>
  </tr>
  <tr>
    <td>理财人数</td>
    <td><input type="text" v-model="state.I_Number"></td>
  </tr>
  <tr>
    <td>风险等级</td>
    <td>
      <input type="radio" value="低风险" v-model="state.I_Top" name="a" checked>低风险
      <input type="radio" value="中风险" v-model="state.I_Top" name="a">中风险
      <input type="radio" value="高风险" v-model="state.I_Top" name="a">高风险
    </td>
  </tr>
  <tr>
    <td>利息</td>
    <td>
      <select v-model="state.L_Id">
        <option value="1">0.02</option>
        <option value="2">0.04</option>
        <option value="3">0.06</option>
        <option value="4">0.08</option>
        <option value="5">0.1</option>
      </select>
    </td>
  </tr>
  <tr>
    <td></td>
    <td><input type="button" value="添加理财" @click="add"></td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">

import axios from 'axios';
import {reactive,toRefs} from 'vue'
import { useRouter } from 'vue-router';
const router = useRouter()

const data=reactive({
  state:{
    I_Name:'',
    I_Year:'',
    I_Month:'',
    I_MinMoney:'',
    I_Number:'',
    I_Top:'',
    L_Id:'1'
  }
})

let {state} =toRefs(data)

const add=()=>{
  if(state.value.I_Name==''){
    alert("理财项目名称不能为空")
    return
  }
  if(state.value.I_Year==''){
    alert("年收益不能为空");
    return;
  }
  if(state.value.I_Month==''){
    alert("月收益不能为空");
    return;
  }
  if(state.value.I_MinMoney==''){
    alert("最低金额不能为空");
    return;
  }

  axios({
    url:'http://localhost:62519/api/Default/PostAddInvest',
    method:'post',
    data:state.value
  }).then(res=>{
    if(res.data.data>0){
      alert("添加成功")
      router.push('/show')
    }else{
      alert("添加失败")
    }
  }).catch(err=>{
    console.log(err);
  })
}




</script>

<style scoped>

</style>